package day20.pack1;

import lombok.SneakyThrows;

public class Test {

    @SneakyThrows
    public static void main(String[] args) {
        Counter counter = new Counter();
        Runnable r = ()->{
            for (int i = 0; i < 1000000; i++) {
                try {
                    counter.increment();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        };
        Thread t1 = new Thread(r);
        Thread t2 = new Thread(r);
        Thread t3 = new Thread(r);
        t1.start();// 2MS
        t2.start();// 2MS
        t3.start();// 2MS

        t1.join(); // 阻塞当前行，等待t1线程执行结束后，再往下
        t2.join();
        t3.join();
        System.out.println(counter.getCount());
    }


}
